//
//  MainWindowController.h
//  HiQ
//
//  Created by maxwell pang on 12-7-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "PairChatWindowController.h"
#import "ClusterChatWindowController.h"
#import "BuddyListPacketProcess.h"
#import "BuddyStatusPacketProcess.h"
#import "ListenPortPacketProcess.h"
#import "ClusterListSource.h"
#import "ClusterListPacketCenter.h"
#import "NewDiscussionWindowController.h"
#import "MyOutlineView.h"
#import "FileListenSocket.h"
#import "FileWindowController.h"
#import "HeartBeatPacketProcess.h"
#import "MsgHistoryWindowController.h"
#import "ExitDiscussion.h"

#define ChangeBackgroundImageNotification @"ChangeBackgroundImageNotification"
#define OnOffLine @"OnOffLine"
#define OnFallLine @"OnFallLine"
#define GetNewFriendInformation @"GetNewFriendInformation"

@class AddNewFriendWindowController;
@class AddNewFriendRequestWindowController;
@class AddNewFriendCenter;

@interface MainWindowController : NSWindowController
{
    IBOutlet NSView *buddyView;
    IBOutlet NSView *clusterView;
    IBOutlet NSToolbar *toolbar;
//    IBOutlet NSTableView *mainTableView;
    Buddy *myselfInfo;
    
    IBOutlet NSWindow *mainWindow;      // normal version
    IBOutlet NSPanel *mainHUDWindow;    // HUD version
    
    NSInteger currentTag;
    NSImage* userImage;
    
//    NSImage *bgImage;
    NSString *bgImageName;
    
    NewDiscussionWindowController     *discussion;
    AddNewFriendWindowController *addNewFriendWindowController;
    NSArray *bgimgs;
    NSUInteger skinNum;
    
    /*file listen*/
    FileListenSocket *fileListenSocket;
    
    // 心跳控制
    NSInteger heartBeatTimeInterval;
    NSTimer *heartBeatTimer;
}

-(IBAction)switchView:(id)sender;
-(IBAction)onAddNewFriend:(id)sender;
-(IBAction)changeBackground:(id)sender;
-(IBAction)onNewDiscussion:(id)sender;
-(IBAction)onExitDiscussion:(id)sender;

- (void) initWithBuddyInfo:(Buddy*)m;

@property NSMutableArray *pairChatArray;
@property NSMutableArray *clusterChatArray;

@property (strong) IBOutlet BuddyListSource *buddySource;
@property (strong) IBOutlet ClusterListSource *clusterSource;
@property ExitDiscussion *exitDiscussion;
@property (weak) IBOutlet MyOutlineView *buddyOutlineView;
@property (weak) IBOutlet MyOutlineView *clusterOutlineView;
@property (retain)GCDAsyncSocket  *listenSocket;
@property BuddyListPacketProcess *buddyListPacketProcess;
@property BuddyStatusPacketProcess *buddyStatusPacketProcess;
@property ClusterListPacketCenter *clusterListPacketCenter;
@property ListenPortPacketProcess *listenPortPacketProcess;
@property Buddy *myselfInfo;
@property (strong)FileWindowController *fileWindowController;  //文件面板窗体
@property (strong)MsgHistoryWindowController *msgWindowController;  //消息记录窗体
@property HeartBeatPacketProcess *heartBeatPacketProcess;
@property AddNewFriendWindowController *addNewFriendWindowController;
@property AddNewFriendRequestWindowController *addNewFriendRequestWindowController;
@property AddNewFriendCenter *addNewFriendCenter;
@property NSAlert *isAddNewFriendAccept;



-(void) openPairChatWindow:(Buddy *)selectedItem;
-(void) onChangeLogin;
+(id) sharedMainWindowController;
+(id) shareMyselfInfo;
- (void) prepareWindowForGrowl:(NSInteger)pQ chatMessage:(NSString*)chatMsg;
-(void) prepareClusterWindowForGrowl:(NSInteger)groupId chatMessage:(NSString *)chatMsg;
- (void)prepareAddNewFriendWindowForGrowl:(NSInteger)userId to:(NSInteger)to;
- (void)prepareIsAcceptAddNewFriendWindowForGrowl:(NSInteger)isAccept fromId:(NSInteger)fromId to:(NSInteger)toId;
- (void) showChatWindow:(NSUInteger) index;
-(void) showClusterChatWindow:(NSUInteger) index;
- (void)showNewFriendRequest;
- (void)showIsAcceptNewFriendRequest;
- (void) changeBackgroundImage:(NSNotification*)notification;
NSImage* GrayImageFromNSImage(NSImage*image);
NSImage* GrayImageFromNSImageWithAlpha(NSImage*image);
NSImage* nsImageFromCGImageRef(CGImageRef image);
CGImageRef CGImageRefCopyFromNSImage(NSImage* image);
CGImageRef SourceDataImageRefCopyFromCGImageRef(CGImageRef img);
CGImageRef AlphaDataImageRefCopyFromCGImageRef(CGImageRef img);
- (void) onFallLine:(NSNotification *)notification;    // 掉线弹窗

@end